package com.hxkcloud.patient.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hxkcloud.patient.R;
import com.hxkcloud.patient.beans.MyFollowBean;

import java.util.List;

/**
 * Created by ray_lei on 2016/7/14.
 */
public class MyFollowAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {


    private Context mContext;
    private List<MyFollowBean> datas;
    private RecyclerView recyclerview;
    private LayoutInflater mInflater;

    private ResultSelectedListener listener;

    public MyFollowAdapter(Context mContext, List<MyFollowBean> datas,
                           RecyclerView recyclerview, ResultSelectedListener listener) {
        this.mContext = mContext;
        this.datas = datas;
        this.recyclerview = recyclerview;
        this.listener = listener;
        mInflater = LayoutInflater.from(mContext);
    }

    public void setData(List<MyFollowBean> datas) {
        this.datas = datas;
        notifyDataSetChanged();
    }

    public void clearData() {
        datas.clear();
        notifyDataSetChanged();
    }

    @Override
    public int getItemCount() {
        // TODO Auto-generated method stub
        return datas.size();
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        // TODO Auto-generated method stub


        Holder mHolder = (Holder) holder;
        mHolder.titleTV.setText(datas.get(position).getTitle());
        mHolder.dateTV.setText("发送时间：" + datas.get(position).getDate());
        mHolder.layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.onSelected("click", datas.get(position));
            }
        });
        mHolder.text_dsc.setText(datas.get(position).getGrade());
        Log.i("--DDD-->","type:"+datas.get(position).getAnswerType());

        /**
         * answerType 1 管理员 2 是护士回答  3 是用户自己的回答
         */
        if(datas.get(position).getAnswerType() == 2)
        {
            mHolder.text_man.setText("评测人：" + datas.get(position).getAnswererName());
        }else
        {
            mHolder.text_man.setText(datas.get(position).getAnswererName());
        }

        if (!TextUtils.isEmpty(datas.get(position).getScore()))
            mHolder.text_score.setText(datas.get(position).getScore() + "分");
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {


        View v = mInflater.inflate(R.layout.item_myfollow_layout, null);
        RecyclerView.ViewHolder holer = new Holder(v);

        return holer;
    }

    @Override
    public int getItemViewType(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    /*
     * Holder
     */
    public class Holder extends RecyclerView.ViewHolder {

        private LinearLayout layout;
        private TextView titleTV;
        private TextView dateTV;
        private TextView text_dsc;
        private TextView text_man;
        private TextView text_score;

        public Holder(View view) {
            super(view);
            layout = (LinearLayout) view.findViewById(R.id.myfollow_layout_item);
            titleTV = (TextView) view.findViewById(R.id.myfollow_tv_title);
            dateTV = (TextView) view.findViewById(R.id.myfollow_tv_time);
            text_dsc = (TextView) view.findViewById(R.id.text_dsc);
            text_man = (TextView) view.findViewById(R.id.text_man);
            text_score = (TextView) view.findViewById(R.id.text_score);
        }
    }

    public interface ResultSelectedListener {
        void onSelected(String type, MyFollowBean info);
    }


}
